package com.zx.idc.backend.gui.api.commom.factory;

import com.zx.idc.backend.gui.api.commom.factory.compression.Compression;
import com.zx.idc.backend.gui.api.commom.factory.compression.NotCompressionImpl;
import com.zx.idc.backend.gui.api.commom.factory.compression.ZIPCompressionImpl;

import java.util.HashMap;

/**
 * Created by hasee on 2019/2/20.
 */
public class CompressionProvider {
    private static final HashMap<Integer, Compression> COMPRESSION_HASH_MAP;

    static {
        COMPRESSION_HASH_MAP = new HashMap<>();
        COMPRESSION_HASH_MAP.put(1, new ZIPCompressionImpl());
        COMPRESSION_HASH_MAP.put(0, new NotCompressionImpl());
    }

    /**
     * 压缩
     * @param compressionFormat
     * @param str
     * @return
     */
    public static byte[] enCMP(int compressionFormat, String str) {
        Compression compression = COMPRESSION_HASH_MAP.get(compressionFormat);
        return compression.enCmp(str);
    }

    /**
     * 解压
     * @param compressionFormat
     * @param str
     * @return
     */
    public static String deCMP(int compressionFormat, byte[] str) {
        Compression compression = COMPRESSION_HASH_MAP.get(compressionFormat);
        return compression.deCmp(str);
    }
}
